package com.csgc.camera.widget.dialog

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.adapter.FilterAdapter
import com.csgc.camera.widget.dialog.base.BottomDialog
import com.cysd.spsyxj.R


class FilterChooseDialog(val context:Context) {

    private lateinit var mDialog: BottomDialog
    private var filterList:RecyclerView?=null
    private var adapter:FilterAdapter?=null

    init {
        initDialog()
    }

    private fun initDialog(){
        mDialog = BottomDialog(context, R.style.FilterDialogTheme).apply {
            setCustomView(R.layout.dialog_filter_choose)
            findViewById<View>(R.id.tv_filter_cancel)?.clickWithTrigger { dismissDialog() }
            filterList = findViewById(R.id.rv_filter_list)
            filterList?.layoutManager = GridLayoutManager(context,2)
            adapter =  FilterAdapter(context)
            filterList?.adapter = adapter
//            setCancelable(false)

        }
    }

    fun setListener(listener:OnFilterChooseListener){
        adapter?.listener = listener
    }

    fun show(){
        mDialog.show()
    }
    fun dismissDialog(){
        mDialog.dismiss()
    }

    fun refreshFilterView(){
        adapter?.notifyDataSetChanged()
    }

    interface OnFilterChooseListener{
        fun onItemCLick(filter:String)
    }
}